home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2786 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What should be returned?
  5. Date: Wed, 24 Jan 1996 01:08:21 GMT
  6. Organization: Netcom
  7. Message-ID: <31058639.183094720@nntp.ix.netcom.com>
  8. References: <4dj8pv$cjd@eng_ser1.erg.cuhk.hk> <30fd5c1a.5495936@nntp.ix.netcom.com> <4dnf7d$1sa@fountain.mindlink.net> <310551bb.169614464@nntp.ix.netcom.com>
  9. NNTP-Posting-Host: ix-dc16-15.ix.netcom.com
  10. X-NETCOM-Date: Tue Jan 23  5:08:22 PM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. I wrote:
  14.  
  15. > genew@mindlink.bc.ca (Gene Wirchenko) wrote:
  16. > > miker3@ix.netcom.com (Mike Rubenstein) wrote:
  17. > > >In fact, it's even legal to have neither a return or exit():
  18. > > 
  19. > > >    int main(void)
  20. > > >    {
  21. > > >    }
  22. > > 
  23. > > >This will return an undefined value to the operating environment, but
  24. > > >does not result in undefined behavior and will not do damage.  I
  25. > > 
  26. > >      Returning an undefined value doesn't result in undefined
  27. > > bahavior?  You been smokin' sumthin' funny, boy?
  28. > >      What happens if/when the return value is interrogated as in
  29. > > MS-DOS's ERRORLEVEL or <other OS>'s <appropriate feature>?
  30. > I've not been smoking anything -- I've just been reading the standard
  31. > in which returning an undefined value does not result in undefined
  32. > behavior.  First, there is no requirement in the standard that the
  33. > operating system or shell use the returned value.  
  34. > Furthermore, the standard does not define what the operating system
  35. > does with any value, including 0, EXIT_SUCCESS, or EXIT_FAILURE simply
  36. > because that is beyond the scope of the standard.
  37. > The standard is very clear (ISO 5.1.2.2.3):
  38. >     If the main function executes a return that specifies no 
  39. >     value, the termination status to the host environment is 
  40. >     undefined.
  41. > It does not say the behavior is undefined, it does not say that the
  42. > main function shall return a value, and it does not leave undefined
  43. > the effect of returning no value.  These are the only ways the
  44. > stadnard indicates undefined behavior (ISO 3.17), so returning no
  45. > value does not result in undefined value.
  46.  
  47. Of course the last sentence should read:
  48.  
  49.     These are the only ways the standard indicates undefined
  50.     behavior (ISO 3.17), so returning no value does not result in
  51.     undefined behavior.
  52.  
  53.  
  54. Michael M Rubenstein
  55.